package edu.sandau.basic.service.impl;

import edu.sandau.basic.mapper.RoleMenuMapper;
import edu.sandau.basic.service.RoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class RoleMenuServiceImpl implements RoleMenuService {

    @Autowired
    private RoleMenuMapper roleMenuMapper;

    @Override
    public List<Integer> getMenuIdsByRole(Integer roleId) {
        return roleMenuMapper.selectMenuIdsByRoleId(roleId);
    }

    @Override
    @Transactional
    public void updateRoleMenus(Integer roleId, List<Integer> menuIds) {
        roleMenuMapper.deleteRoleMenus(roleId);
        if (menuIds != null && !menuIds.isEmpty()) {
            roleMenuMapper.insertRoleMenus(roleId, menuIds);
        }
    }

    @Override
    @Transactional
    public void deleteRoleMenus(Integer roleId) {
        roleMenuMapper.deleteRoleMenus(roleId);
    }
}
